<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<div class="modal-dialog ms-modal-dialog" style="margin-top:50px;" >
  <div class="modal-content">
     
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <h4 class="modal-title">修改自定义课程</h4>
    </div>
    
      <form class="form-horizontal ms-form form-personal-info" method="POST" action="${ctx.host}/project-data/${projectPhaseCourse.id}/edit-course" data-validate="true">
        <input type="hidden" name="projectPhaseCourseId" value="${projectPhaseCourse.id}" />
        <input type="hidden" name="_method" value="PATCH" />
        <input type="hidden" name="trainerId" value="${persist.idmUserByEmail(projectPhaseCourse.trainer.email).id}" />
        
         <div class="modal-body">
             
            <div class="form-group  ms-form-group">
	          <label class="control-label col-xs-3"><span class="text-red">*</span>课程名称：</label>
	          <div class="col-xs-8">
	            <input type="text" class="form-control" name="name" value="${projectPhaseCourse.course.name}" placeholder="名称" data-validate="required" autocomplete="off" tabindex="1"/>
	          </div>
	        </div>
	        
	        <div class="form-group  ms-form-group">
	          <label class="control-label col-xs-3"><span class="text-red">*</span>课程时长：</label>
	          <div class="col-xs-8">
	            <input type="text" class="form-control" name="hour" value="${projectPhaseCourse.course.hour}" placeholder="课程时长" data-validate="required|float|length_between,1,4" autocomplete="off" tabindex="2"/>
	          </div>
	        </div>
	        
            <div class="form-group  ms-form-group">
	          <label class="control-label col-xs-3"><span class="text-red">*</span>课程目标：</label>
	          <div class="col-xs-8">
	          	<textarea name="target" cols="45" rows="4" style="OVERFLOW: hidden">${projectPhaseCourse.course.target}</textarea>
	            <!--<input type="text" class="form-control" name="target" value="" placeholder="课程目标" data-validate="required" autocomplete="off" tabindex="3"/>-->
	          </div>
	        </div>
	        
            <div class="form-group  ms-form-group">
	          <label class="control-label col-xs-3"><span class="text-red">*</span>课程介绍：</label>
	          <div class="col-xs-8">
	          	<textarea name="description" cols="45" rows="4" style="OVERFLOW: hidden">${projectPhaseCourse.course.description}</textarea>
	            <!--<input type="text" class="form-control" name="description" value="" placeholder="课程介绍" data-validate="required" autocomplete="off" tabindex="3"/>-->
	          </div>
	        </div>
	        
	        <div class="form-group  ms-form-group">
					<label class="control-label col-xs-3">原讲师：</label>
					<div class="col-xs-8 pull-left">
						<p class="form-control-static">${projectPhaseCourse.trainer.name}&nbsp;-&nbsp;${projectPhaseCourse.trainer.email}&nbsp;&nbsp;
            <a class="edit-trainer">修改</a>
						</p>
					</div>
				</div>
	        
	         <div class="form-group  ms-form-group new-trainer hide">
	          <label class="control-label col-xs-3"><span class="text-red">*</span>讲师：</label>
	          <div class="col-xs-8">
					<input class="select2 form-control" name="selectTrainerId" id="trainerId" tabindex="7" placeholder="不更改讲师请勿选择">
	          </div>
	        </div>
	       
	        <div class="form-group  ms-form-group">
	          <label class="control-label col-xs-3"><span class="text-red">*</span>课程类型：</label>
	          <div class="col-xs-8">
					<select class="select2 form-control" name="type" tabindex="7" data-validate="required">
					    <option></option>
		                <option value="管理类" ${projectPhaseCourse.course.type eq '管理类' ? 'selected' : ''}>管理类</option>
		                <option value="专业通识类" ${projectPhaseCourse.course.type eq '专业通识类' ? 'selected' : ''}>专业通识类</option>
		            </select>
	          </div>
	        </div>
        
        </div>
      <div class="modal-footer ms-modal-footer">
        <button type="submit" class="btn btn-shadow-success btn-shadow umu-btn" >确定</button>
        <button type="button" class="btn btn-shadow-default btn-shadow umu-btn" data-dismiss="modal">取消</button>
      </div>

      </form>
    
  </div>
</div>
<script type="text/javascript">
 $(document).ready(function() {
	 $('select[name="type"]').select2({
         placeholder : '请选择课程类型',
         minimumResultsForSearch : 1,
         allowClear : true,
	 }); 
      $('#trainerId').select2({
         placeholder : '不更改讲师请勿选择',
         minimumResultsForSearch : 1,
         minimumInputLength: 2,
         allowClear : true,
         ajax: {
             type:'GET',
             url: function(params){      
            	 console.log(params)
                 return window.__CTX__.root + '/trainers/select-search?query='+ params
             },
             dataType: 'json',
             delay: 1500,
             results: function (response, page, i) {
               console.log(page)
               console.log(i)
               if(response.code == '0' || response.code == 0) {
            	   return {results: response.data.trainers}
               } else {
            	   return null;
               }
             },
             cache: true
         }
      
       }).on("change", function(e) {
           var selectLead = $("input[name='selectTrainerId']").val();
           $("input[name='trainerId']").val(selectLead)
        })
        
        $(".edit-trainer").click(function() {
        	$(".new-trainer").removeClass("hide");
        })
        
 })
</script>
